package com.lexue.articlesync.repository;

import com.lexue.articlesync.entity.Video;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 视频数据访问接口
 */
@Repository
public interface VideoRepository extends JpaRepository<Video, Long> {
    
    /**
     * 根据状态查找视频
     */
    List<Video> findByStatus(Video.VideoStatus status);
    
    /**
     * 根据标题模糊查询
     */
    List<Video> findByTitleContainingIgnoreCase(String title);
    
    /**
     * 根据标签查询
     */
    @Query("SELECT v FROM Video v WHERE v.tags LIKE %:tag%")
    List<Video> findByTagsContaining(@Param("tag") String tag);
    
    /**
     * 查询定时发布的视频
     */
    @Query("SELECT v FROM Video v WHERE v.status = 'SCHEDULED' AND v.scheduledTime <= :now")
    List<Video> findScheduledVideos(@Param("now") LocalDateTime now);
    
    /**
     * 根据文件路径查询
     */
    Video findByFilePath(String filePath);
    
    /**
     * 根据创建时间范围查询
     */
    List<Video> findByCreatedAtBetween(LocalDateTime startTime, LocalDateTime endTime);
    
    /**
     * 查询最近的视频
     */
    List<Video> findTop10ByOrderByCreatedAtDesc();
}